﻿using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CustomWindowChromeDemo;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void MainWindow_OnStateChanged(object? sender, EventArgs e)
    {
        // // 最大化后屏幕大小
        // Console.WriteLine($"SystemParameters.MaximizedPrimaryScreenHeight: {SystemParameters.MaximizedPrimaryScreenHeight}");
        // Console.WriteLine($"SystemParameters.MaximizedPrimaryScreenWidth: {SystemParameters.MaximizedPrimaryScreenWidth}");
        //
        // Console.WriteLine($"SystemParameters.WorkArea: {SystemParameters.WorkArea}"); // 工作区大小

        if (WindowState == WindowState.Maximized)
        {
            var leftRight = (SystemParameters.MaximizedPrimaryScreenWidth - SystemParameters.WorkArea.Width) / 2d;
            var topBottom = (SystemParameters.MaximizedPrimaryScreenHeight - SystemParameters.WorkArea.Height) / 2d;
            Border.Margin = new Thickness(leftRight, topBottom, leftRight, topBottom);
        }
        else
        {
            Border.Margin = new Thickness(0);
        }

        PrintSystemParametersProperties();
    }
    
    public void PrintSystemParametersProperties()
    {
        var type = typeof(SystemParameters);
        var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static);

        foreach (var property in properties)
        {
            object value = property.GetValue(null);
            Console.WriteLine($"{property.Name}: {value}");
        }
    }

    private void Button_OnClick(object sender, RoutedEventArgs e)
    {
        if (e.OriginalSource is not Button button) return;
        if (button.Content is int value)
        {
            button.Content = value + 1;
        }
        else
        {
            button.Content = 1;
        }
    }
}